//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
   cityName:'',
   list:{}
  },
  city:function(e){
     this.setData({
       cityName: e.detail.value
     })
  },
  callRes:function(){
    var that = this;
    var reg = /^[A-Za-z]+$/;
    if (this.data.cityName == '' || reg.test(this.data.cityName)){
      return
    }
    wx.request({
      url: 'https://www.sojson.com/open/api/weather/json.shtml', 
      data: {
        city: this.data.cityName
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          list: res.data.data.forecast
        });
      },
      fail:function(res){
        console.log("fail")
      }
    })
  }
})
